/*病人危急值JS*/

function refreashCritical(){
	layer.msg('刷新中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500,skin: 'layui-layer-msg16'});
	loadCriticalData();
}
function loadCriticalData(){
	 debugger;
	  var url = mqUrl+"/Mq/MQRisPacs/queryVJ";
		var params = {};
	 	params.ACF01 = 1;
	 	params.VAA01 = $("#vaa01").val();
	 	params.jsessionids=jsessionids;
		 $.ajax({
			 url : url,
			 type : "get",
			 dataType : 'jsonp',
			 data :params,
			 timeout : 1000, //超时
			 success : function(data){
				 if (data.state == "success") {
					 var list = data.list;
					 loadCriticalJqgride(list);
				 }
			}
			
		 })	
}
function loadCriticalJqgride(list){
	var tname = 'critical_value_table';
	$('#critical_value_container').resize(function(){
		$("#critical_value_table").setGridWidth($("#critical_value_container").width()*1);
	});
    jQuery('#critical_value_table').GridUnload();
    jQuery("#critical_value_table").jqGrid({
         datatype: 'local', 
     	 data:list,
     	 height : 'auto',
    	 width : 'auto',
    	 autowidth : true,
    	 forceFit:true,
         shrinkToFit:true,
         colModel: [
             {
				label : "操作",
				name : 'receive',
				width:"85",
				align: "center",
				 cellattr: function(rowId, tv, rawObject, cm, rdata) {
			         return 'id='+tname+'_receive' + rowId;
			     }
			 },
             {label: '分类',name: 'type',align: "center",width:'60',
            	 
	            formatter:function(cellvalue, options, rowObject){
	            	switch (cellvalue)
	            	{
	            		case 'jyvj' :
	            			return "检验";
	            			break;
	            		case 'jcvj' :
	            			return "检查";
	            			break;
	            		default :
	            			return "";
	            			break;
	            	}
	            }
            	 
             },
             {label: '姓名',name: 'vaa05',sortable:false},
             {label: '项目',name: 'BBX05',sortable:false,width:"300"},
             {label: '结果',name: 'LAC10',sortable:false},
             {label: '单位',name: '',sortable:false,width:'60'},
             {label: '危急状态',name: 'LAC12',sortable:false,width:'100'},
             {label: '危急低值',name: 'LAC29'},
             {label: '危急高值',name: 'LAC30'},
             {label: '检验时间',name: 'LAB20'},
             {label: '审核时间',name: 'LTI11'},
             {label: '送检医生',name: 'LTI07'},
             {label: '消息接收人',name: 'LTI13'},
             {label: '消息接收时间',name: 'LTI14'},
             {label: '备注',name: 'LTI28'},
             {label: '电话提醒人',name: 'LTI16'},
             {label: '电话通知时间',name: 'LTI17'},
             {label: 'lac01',name: 'lac01',hidden:true}
         ],
         rowNum: list.length,
         sortname: 'BBX05',
         onSelectRow: function (id) {
         },
         loadComplete: function (data) {
        	 debugger;
        	//无数据的时候展示暂无数据信息
 			if (data.rows.length<1) {
 				var $tr = $("#critical_value_table").find('tbody>tr:last');
 				var len = $tr.find('td').length;
 				$("#critical_value_table").html('<tr><td colspan="'+ parseInt(len)+ '" style="text-align:left;">没有符合条件的数据！</td></tr>');
 			}else{
 				var ids = jQuery("#critical_value_table").jqGrid('getDataIDs');
 				for (var i = 0; i < ids.length; i++)
 				{
 					var cl = ids[i];
 					var receiveInput = "<button class='btn btn-min btn-white' onclick='receiveRow(this)' >接收</button>";
 					jQuery("#critical_value_table").jqGrid('setRowData', ids[i],
 							{
 								receive : receiveInput
 							});
 				}
 			}

         },
         loadError:function(xhr,status,error){
        	 /*layer.msg('危急值服务连接失败！', {
 				time : 2000,
 				icon : 0,
 				skin : 'layui-layer-msg0'
 			});*/
         }

     });
}
function receiveRow(that)
{
	layer.msg('接收中....', {icon: 16,shade: [0.1, '#393D49'],time:1*500,skin: 'layui-layer-msg16'});
	var rowid = $(that).parents("tr").attr("id");
	var rowdata = $("#critical_value_table").jqGrid("getRowData", rowid);
	if(rowdata.LTI13){
		layer.msg('该信息已经被接收！', {
				time : 4000,
				icon : 0,
				skin : 'layui-layer-msg0'
		})
		return false;
	}
	var url = mqUrl+"/Mq/MQRisPacs/updateVJZ";
	var params = {};
 	params.LAC01 = rowdata.lac01;
 	params.VAA05 = trueName;
 	params.type = rowdata.type == "检查"?2:1;
 	params.jsessionids=jsessionids;
	 $.ajax({
		 url : url,
		 type : "get",
		 dataType : 'jsonp',
		 data :params,
		 timeout : 1000, //超时
		 success : function(data){
			 if (data.state == "success") {
				 var list = data.list;
				 loadCriticalData();
			 }
		}
		
	 })	
}






